<?php

namespace App\Http\Controllers;


use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller;

class BaseController extends Controller
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $validation;

    /**
     * @param array $data
     * @param array $rules
     * @param array $messages
     * @return string|null
     */
    protected function validator($data, $rules, $messages = [])
    {
        foreach ($rules as &$rule) {
            if (is_array($rule)) {
                $rule = array_values($rule);
            }
        }

        $this->validation = $this->getValidationFactory();

        $validator = $this->validation->make($data, $rules, $messages);
        if ($validator->fails()) {
            return $validator->errors()->first();
        }
        return null;
    }

}


